﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms;

namespace MacomberMapSystem.Common.User_Interfaces.Editors
{
    /// <summary>
    /// This class offers an HTML type editor
    /// </summary>
    public class MM_HTML_TypeEditor : UITypeEditor
    {
        /// <summary>
        /// Report the editing style for our control
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        /// <summary>
        /// Allow editing of our folder, converting paths from local to UNC paths if not on this machine.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {

            using (Form DisplayForm = new Form())
            {
                String CurValue = Convert.ToString(value);
                SplitContainer splMain = new SplitContainer();
                splMain.Dock = DockStyle.Fill;
                splMain.Orientation = Orientation.Horizontal;
                splMain.Panel1.Controls.Add(new MM_HTML_Editor() { Dock = DockStyle.Fill, HTML = CurValue });
                splMain.Panel2.Controls.Add(new Button() { Text = "Ok", DialogResult = System.Windows.Forms.DialogResult.OK });
                splMain.Panel2.Controls.Add(new Button() { Text = "Cancel", DialogResult = System.Windows.Forms.DialogResult.Cancel, Left = splMain.Panel2.Controls[0].Right + 5 });
                splMain.FixedPanel = FixedPanel.Panel2;
                splMain.SplitterDistance = splMain.Height - splMain.Panel2.Controls[0].Height - 10;
                DisplayForm.Controls.Add(splMain);
                DisplayForm.AcceptButton = splMain.Panel2.Controls[0] as Button;
                DisplayForm.CancelButton = splMain.Panel2.Controls[1] as Button;
                if (DisplayForm.ShowDialog() == DialogResult.OK)
                    return (splMain.Panel1.Controls[0] as MM_HTML_Editor).HTML;
                else
                    return CurValue;
            }
        }
    }
}